home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 27 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: colossus.holonet.net!tglbbs!charles.herold
  2. From: charles.herold@tglbbs.com (Charles Herold)
  3. Newsgroups: comp.lang.c
  4. Subject: switching array pointers query
  5. Date: Sun, 31 Dec 1995 16:48:23 GMT
  6. Message-ID: <95123120361029516@tglbbs.com>
  7. Organization: TGL BBS 3 Nodes of Fun 212-974-3925, 212-765-2524, 212-541-5596
  8. Distribution: world
  9.  
  10. My struggle with arrays of pointers and such not continues, and here's
  11. an example of my difficulties.  Below is a bit of code that works, after
  12. trying various ways that didn't work.  However, it doesn't do what I
  13. want quite the way I intended.  I have an array of pointers to
  14. structures, and wish to simply reverse the order of the array.  What I
  15. *want* is to simply change what the pointers point to, that is, the
  16. first pointer points to what begins as the last element of the array,
  17. the last points to the first, and so on.  But I couldn't get that, and
  18. you see below that I am simply moving the information in the last
  19. element into where the first pointer is pointing etc.  Since it
  20. does work, it might seem like I could just not worry about it.  But I'm
  21. hoping seeing how this should be done might give me an understanding
  22. breakthrough on this whole pointer to array thing that drives me crazy.
  23.  
  24. Thanks to all who help.
  25.  
  26. void
  27. ReverseFiles( struct find_t **files, int numberfiles )
  28. {
  29.     int i, h;
  30.     struct find_t temp;
  31.  
  32.     for( i = 0, h = numberfiles - 1; i < h; i++, h-- ) {
  33.          temp = (*files)[i];
  34.          (*files)[i] = (*files)[h];
  35.          (*files)[h] = temp;
  36.     }
  37. }
  38.